var $1;
if($1=(opener.$||parent.$)){
	var style = $1("head").find("link[href$=style.css]").attr("href");
	$("head").find("link[href$=style.css]").attr("href",style);
}
	
var isLoadedMore = false;
$(function(){
	var categoryId = $.getParam("category_id");
	var pageno = $.getParam("pageno");
	if(!categoryId){
		var urlName = location.pathname;
        var arr = urlName.split("/");
        categoryId = arr[arr.length-1].split(".")[0];
    }
	bindPage(categoryId,20,pageno,true);
})

//绑定页面数据
function bindPage(categoryId,pagesize,pageno,isTotal){
	pagesize = pagesize||20;
	pageno = pageno||1;
	var url = "/category/"+categoryId+"/entity?fields=entity_id,title,create_date&pagesize="+pagesize+"&pageno="+pageno+"&is_total="+isTotal;
	$.get(url,function(json){
        var data = json;
        data = data.result || [];
        var html = [];
        document.title = json.name;
        html.push("<h3><span class='fl h3_cn'>" + json.name + "</span></h3><div class='innew_line'><ul>");
        for(var i=0;i<data.length;i++){
			var d = data[i];
			var entityId = d.entity_id;
			var title = d.title;
	        var createDate = d.create_date;
	        html.push("<li><a href='_"+entityId+".html' class='fl' target='_blank' title='"+title+"'>" + title +"</a><time class='newline_time'>"+createDate+"</time></li>");
        }
        html.push("</ul></div>");
        $("#content").html(html.join(""));
        
        if(json.total>1 && !isLoadedMore){
        	$("#content").after("<div id='pagebar'></div>");
        	$.pageBar('pagebar',json.total,pagesize,pageno,function(pageindex){
				bindPage(categoryId,pagesize,pageindex);
			})
			isLoadedMore = true;
        }
    });
}